package com.lab.network.proxy;

import com.lab.network.model.CtApiResponse;
import com.lab.network.model.IProxyCallback;
import com.lab.network.model.ProxyResult;

import java.util.Map;

/**
 * Created by MiJack on 2015/11/20.
 */
public class ProxyCallBackImpl implements IProxyCallback {
    private Map<String, IProxyCallback> map;

    public ProxyCallBackImpl(Map<String, IProxyCallback> map) {
        this.map = map;
    }

    @Override
    public boolean onProxyResult(ProxyResult<?> result) {
        CtApiResponse response = (CtApiResponse) result.getData();
        IProxyCallback callback = map.get(response.getApiName());
        if (callback != null) {
            return callback.onProxyResult(result);
        } else {
            throw new RuntimeException("Api "+response.getApiName() +" is not added in this callback map , please add it . ");
        }
    }
}
